package com.sunrate.investingquote.service.router.comparator.test;

import com.sunrate.investingquote.bean.router.ChannelPriorityConfig;
import com.sunrate.investingquote.bean.router.ChannelRouter;
import com.sunrate.investingquote.dto.router.comparator.RouterSortContext;
import com.sunrate.investingquote.enums.RouterPriorityEnum;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.Map;

/**
 * @author yyh
 * @description:
 * @date 2023/06/30/ 9:57
 */
public class FeeRateComparator implements RouterComparator<RouterSortContext<ChannelRouter>, Map<String, ChannelPriorityConfig>> {

    @Override
    public RouterPriorityEnum routerPriorityEnum() {
        return RouterPriorityEnum.FEE_RATE;
    }

    @Override
    public Comparator<RouterSortContext<ChannelRouter>> createComparator(Map<String, ChannelPriorityConfig> context) {
        if (!context.containsKey(routerPriorityEnum().getCode())) {
            return Comparator.comparing(RouterSortContext::getFeeRate);
        }
        return null;
    }
}
